package com.travel.photos.ui.otheruser;

import android.content.Context;
import android.widget.Toast;

import com.travel.photos.bean.OtherUserBean;
import com.travel.photos.bean.PhotoRecommentBean;
import com.travel.photos.config.UrlConfig;
import com.travel.photos.ui.recommend.RecommendContract;
import com.travel.photos.ui.recommend.RecommendModel;
import com.travel.photos.ui.recommend.RecommentAdapter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import rx.Subscriber;


/**
 * Created by Administrator on 2016/10/17.
 */
public class OtherUserPresenter implements OtherUserContract.Presenter {
//逻辑处理
    private OtherUserContract.View view;
    private OtherUserContract.Model model;
    private String userid;

    public OtherUserPresenter(OtherUserContract.View view,String userid) {
        this.view = view;
        this.model = new OtherUserModel();
        this.userid = userid;
    }

    private String page="1";
    private String nextpage;

    private Map<String,String> map = new HashMap<>();
    private List<OtherUserBean.DataBean.ListBean> traveresbeans;
    private OtherUserAdapter adapter;

    @Override
    public void getDetail(final Context context) {
        map.put(UrlConfig.Params.PARAMTRPE,"get");
        map.put(UrlConfig.Params.PAGE,page);
        map.put(UrlConfig.Params.USERID,userid);

        model.getDetail(map,new Subscriber<OtherUserBean>() {
            @Override
            public void onCompleted() {
            }

            @Override
            public void onError(Throwable e) {
                Toast.makeText(context,"网络taiman,小逗推荐换个wifi试试",Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onNext(OtherUserBean travelDetail) {
                if (page=="1"){
                    traveresbeans = travelDetail.getData().getList();
                    nextpage = travelDetail.getData().getNextPage();
                    adapter= new OtherUserAdapter(context,traveresbeans);
                    view.getDetail(adapter);
                }else {
                    traveresbeans.addAll(travelDetail.getData().getList());
                    adapter.notifyDataSetChanged();
                }
            }
        });
    }
    public void UpRefresh(Context context){
        page=nextpage;
        getDetail(context);
    }
}
